package com.xuxin.baby;

import android.app.Application;
import android.database.sqlite.SQLiteDatabase;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.PathUtils;
import com.blankj.utilcode.util.Utils;
import com.greendao.dao.DaoMaster;
import com.greendao.dao.DaoSession;
import com.uuzuche.lib_zxing.activity.ZXingLibrary;
import com.xuxin.baby.base.BaseConstant;

/**
 * Created by xu_xin
 * Created on 2020.06.05
 */
public class App extends Application {
    private static App app;

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        initUtils();
        initGreenDao();
    }

    public static App getInstance() {
        return app;
    }

    private void initUtils() {
        Utils.init(this);
        LogUtils.getConfig().setLogSwitch(BaseConstant.is_debug);
        LogUtils.getConfig().setConsoleSwitch(BaseConstant.is_debug);
        LogUtils.getConfig().setGlobalTag("xu_xin");
        LogUtils.getConfig().setLogHeadSwitch(false);
        LogUtils.getConfig().setBorderSwitch(false);
        LogUtils.getConfig().setSingleTagSwitch(false);
        ZXingLibrary.initDisplayOpinion(this);
    }

    /**
     * GreenDao
     */
    public DaoSession daoSession;

    public DaoSession getDaoSession() {
        return daoSession;
    }

    private void initGreenDao() {
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "history.db");
        SQLiteDatabase db = helper.getWritableDatabase();
        DaoMaster daoMaster = new DaoMaster(db);
        daoSession = daoMaster.newSession();
        DaoMaster.DevOpenHelper helper2 = new DaoMaster.DevOpenHelper(this, "cart.db");
        SQLiteDatabase db2 = helper2.getWritableDatabase();
        DaoMaster daoMaster2 = new DaoMaster(db2);
        daoSession = daoMaster2.newSession();
        DaoMaster.DevOpenHelper helper3 = new DaoMaster.DevOpenHelper(this, "search.db");
        SQLiteDatabase db3 = helper3.getWritableDatabase();
        DaoMaster daoMaster3 = new DaoMaster(db3);
        daoSession = daoMaster3.newSession();
    }
}